import { createRouter, createWebHistory } from 'vue-router'
import VueCookie from 'vue-cookie'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/index',
      name: 'Index',
	  redirect:'/lunbo',
      component: () => import("@/views"),
	 children: [
			{
				path: '/lunbo',
				name: 'Lunbo',
				component: () => import('@/views/lunbo')
			},
	 		{
	 		    path: '/user',
	 		    name: 'User',
	 		    component: () => import("@/views/PermissionsM/user")
	 		}  ,
			{
				path: '/role',
				name: '/Role',
				component: () => import("@/views/PermissionsM/role")
 			},
			{
				path: '/res',
				name: '/Rea',
				component: () => import("@/views/PermissionsM/res")
			},
			{
				path: '/AdministratorLL',
				name: '/AdministratorLL',
				component: () => import("@/views/System/AdministratorLL")
			},
			{
				path: '/UserLL',
				name: '/UserLL',
				component: () => import("@/views/System/UserLL")
			},	
			{
				path: '/sales',
				name: '/sales',
				component: () => import("@/views/Statistics/sales")
			},	{
				path: '/visitors',
				name: '/visitors',
				component: () => import("@/views/Statistics/sales/goodsRegion.vue")
			},
		
			{
				path: '/membership',
				name: 'membership',
				component: () => import("@/views/MembershipM/index.vue")
			},
		 {
				path: '/summery',
				name: 'summery',
				component: () => import("@/views/MembershipM/summery.vue")
			},
			{
				path: '/region',
				name: 'region',
				component: () => import("@/views/TerritoryM/region")
			},
			{
				path: '/stores',
				name: 'stores',
				component: () => import("@/views/TerritoryM/stores")
			},
			{

			  path: '/notice',
			  name: 'NoticeList',
			  component: () => import('@/views/Community/inf/notice')
			},
			{
				path: '/topic',
				name: 'Topic',
				component: () => import('@/views/Community/inf/topic')
			},
			{
				path: '/complaint',
				name: 'ComplaintList',
				component: () => import('@/views/Community/inf/complaint')
			},
			{
				path: '/repair',
				name: 'RepairtList',
				component: () => import('@/views/Community/property/repair')
			},
			{
				path: '/parkingSpace',
				name: 'ParkingList',
				component: () => import('@/views/Community/sec/parking')
			},
			{
				path: '/visitor',
				name: 'VisitorList',
				component: () => import('@/views/Community/sec/visitor')
			},
			{
				// path没加/，则需要/index/goods才能访问，如果加了/则不需要加/index
				path: '/goods',
				name: 'Goods',
				component: () => import('@/views/MerchandiseM/goods')
			},
			{
				path: '/category',
				name: 'Category',
				component: () => import('@/views/MerchandiseM/category')
			},
			{
				path: '/marketing',
				name: 'Marketing',
				component: () => import('@/views/MerchandiseM/marketing')
			},
			{
				path: '/order',
				name: 'OrderManage',
				component: () => import('@/views/OrderManage')
			}
	 ]
    },
	{
		path: '/',
		name: 'Login',
		component: () => import('@/views/Login')
	}
  ]
})
router.beforeEach((to,from,next) => {
	const token = VueCookie.get('token')
	if(to.fullPath === '/' || token){
		next()
		return
	}
	next('/')
})
export default router
